home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / CHOOSECO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.7 KB  |  95 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.8  $
  6. //
  7. // Implementation of TChooseColorDialog, a Choose Color Common Dialog class
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_CHOOSECO_H)
  11. # include <owl/chooseco.h>
  12. #endif
  13.  
  14. OWL_DIAGINFO;
  15. DIAG_DECLARE_GROUP(OwlCommDialog);  // diagnostic group for common dialogs
  16.  
  17. uint TChooseColorDialog::SetRGBMsgId = 0;
  18.  
  19. DEFINE_RESPONSE_TABLE1(TChooseColorDialog, TCommonDialog)
  20. END_RESPONSE_TABLE;
  21.  
  22. IMPLEMENT_CASTABLE(TChooseColorDialog);
  23.  
  24. //
  25. // Initialize the choose color common dialog data members.
  26. //
  27. TChooseColorDialog::TChooseColorDialog(TWindow*        parent,
  28.                                        TData&          data,
  29.                                        TResId          templateId,
  30.                                        const char far* title,
  31.                                        TModule*        module)
  32. :
  33.   TCommonDialog(parent, title, module),
  34.   Data(data)
  35. {
  36.   if (!SetRGBMsgId)
  37.     SetRGBMsgId = ::RegisterWindowMessage(SETRGBSTRING);
  38.  
  39.   memset(&Cc, 0, sizeof Cc);
  40.   Cc.lStructSize = sizeof Cc;
  41.   Cc.hwndOwner = Parent ? Parent->GetHandle() : 0;
  42.   Cc.hInstance = HWND(GetModule()->GetHandle());  // hInstance is badly typed
  43.   Cc.Flags = CC_ENABLEHOOK | Data.Flags;
  44.   if (templateId) {
  45.     Cc.lpTemplateName = templateId;
  46.     Cc.Flags |= CC_ENABLETEMPLATE;
  47.   }
  48.   else
  49.     Cc.Flags &= ~CC_ENABLETEMPLATE;
  50.   Cc.lpfnHook = 0;
  51.  
  52.   Cc.rgbResult = Data.Color;
  53.   Cc.lpCustColors = (COLORREF far*)Data.CustColors;
  54.  
  55.   TRACEX(OwlCommDialog, OWL_CDLEVEL, "TChooseColorDialog constructed @" << (void*)this);
  56. }
  57.  
  58. //
  59. // Destructor does nothing in non diagnostic versions of the library.
  60. // In the diagnostic version, it displays a trace message.
  61. //
  62. TChooseColorDialog::~TChooseColorDialog()
  63. {
  64.   TRACEX(OwlCommDialog, OWL_CDLEVEL, "TChooseColorDialog destructed @" << (void*)this);
  65. }
  66.  
  67. //
  68. // Override the virtual DialogFunction.
  69. // Does no additional processing.
  70. //
  71. bool
  72. TChooseColorDialog::DialogFunction(uint msg, TParam1 param1, TParam2 param2)
  73. {
  74.   return TCommonDialog::DialogFunction(msg, param1, param2);
  75. }
  76.  
  77. //
  78. // Execute the dialog to retrieve user's choice of color.
  79. //
  80. int
  81. TChooseColorDialog::DoExecute()
  82. {
  83.   Cc.lpfnHook = LPCCHOOKPROC(StdDlgProc);
  84.   int ret = ::ChooseColor(&Cc);
  85.   if (ret) {
  86.     Data.Flags = Cc.Flags;
  87.     Data.Error = 0;
  88.     Data.Color = Cc.rgbResult;
  89.   }
  90.   else {
  91.     Data.Error = ::CommDlgExtendedError();
  92.   }
  93.   return ret ? IDOK : IDCANCEL;
  94. }
  95.